package com.bwie.es.synchronization;

import com.alibaba.fastjson.JSON;
import com.bwie.common.domain.request.ProductRequest;
import com.bwie.common.result.Result;
import com.bwie.es.feign.ShowFeignController;
import com.bwie.es.service.EsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 *每隔5分钟，全量同步商品信息，把商品信息异步更新到ES索引库当中
 */
@Component
public class TimerAllProduct {
    @Autowired
    private EsService esService;
    @Autowired
    private ShowFeignController feignController;

    @Scheduled(cron = "* */5 * * * ?")
    public void timer(){
        esService.deleteCourseEs();
        Result<List<ProductRequest>> result = feignController.showAll();
        List<ProductRequest> list = result.getData();
        JSON.toJSONString(list);
        esService.insertBatch(list);
    }
}
